package com.ouyang.Service.Impl;

import com.ouyang.Service.CdbService;
import com.ouyang.form.AddOrderForm;
import com.ouyang.mapper.CdbMapper;
import com.ouyang.poji.Orders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CdbServiceImpl implements CdbService {

    @Autowired
    private CdbMapper cdbMapper;

    @Override
    public List<Orders> getcdblist ( ) {
        return cdbMapper.getcdblist();
    }

    @Override
    public List<Orders> search ( String key, String value ) {
        if (key.equals("")) return this.cdbMapper.getcdblist();
        List<Orders> list = null;
        switch (key) {
            case "Id":
                list = cdbMapper.searchById(value);
                break;
            case "OrderNumber":
                list = cdbMapper.searchByon(value);
                break;
            case "cdbName":
                list = cdbMapper.searchByname(value);
                break;
            case "RentPeople":
                list = cdbMapper.searchByrentpeople(value);
                break;
        }
        return list;
    }

    @Override
    public void add ( AddOrderForm orderForm ) {
        try {
            cdbMapper.add(orderForm);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void delete ( String id ) {
        try {
            cdbMapper.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void update ( Orders orders ) {
        try {
            cdbMapper.update(orders);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
